package com.qf.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.entity.TbGoods;
import com.qf.mapper.GoodsMapper;
import com.qf.service.GoodsService;
import com.qianfeng.util.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, TbGoods> implements GoodsService {

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public ResultMsg findAll(int page ,int size) {
        Boolean aBoolean = redisTemplate.hasKey("goods_list");
        List<TbGoods> list=null;
        if(!aBoolean){
            list = super.list();//库
            redisTemplate.opsForList().leftPushAll("goods_list",list);
        }
        int start=(page-1)*size;
        list = redisTemplate.opsForList().range("goods_list",start , start+size);//redis
        return ResultMsg.success(list);
    }
}
